package com.cc.controller;


import com.cc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/users")
@ResponseBody
public class UserRestController {

    //获取所有的用户
    @GetMapping
    public List<User> findList(){
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setId(1);
        user.setAge(18);
        user.setName("娃哈哈");
        user.setSalary(5000);
        users.add(user);

        User user1 = new User();
        user.setId(1);
        user.setAge(18);
        user.setName("娃哈哈");
        user.setSalary(5000);
        users.add(user1);
        return users;
    }

    //获取指定用户
    @GetMapping("/{userId}")
    public User findUser(@PathVariable Integer userId){
        System.out.println("前端传递的userId"+userId);
        User user = new User();
        user.setId(userId);
        user.setAge(18);
        user.setName("娃哈哈1");
        user.setSalary(5000);
//        user.setDateTime();
        return user;
    }
    @PostMapping
    public String save(){

        return "save";
    }
    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Integer userId){
        System.out.println("传入的id"+userId);
        return "delete";
    }
    @PutMapping
    public String put(){

        return "修改需求";
    }

}
